package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 增强型for循环演示
 */
public class NewForDemo {
    public static void main(String[] args) {
        String[] strs = {"hello", "world", "java", "love"};
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
        for (String s : strs) {//s是指数组中的每个元素
            System.out.println(s);
        }


        Collection<String> c = new ArrayList<>();
        c.add("hello");
        c.add("world");
        c.add("java");
        c.add("love");
        Iterator<String> it = c.iterator();
        while (it.hasNext()) {
            String s = it.next();
            System.out.println(s);
        }
        for (String s : c){//s表示的是数组中的每个元素
            System.out.println(s);
        }


    }

}
